import Map from "@arcgis/core/Map";
import MapView from "@arcgis/core/views/MapView";
import WebTileLayer from "@arcgis/core/layers/WebTileLayer";
import "@arcgis/core/assets/esri/themes/light/main.css";
import {
  sjz_road_layer,
  police_layer,
  factory_layer,
  hospital_layer,
  fire_station_layer,
  river_line_layer,
  sjz_county_layer,
  river_area_layer,
} from "@/api/featuresLayers";

let map: __esri.Map, mapView: __esri.MapView;
export const tiledLayer = new WebTileLayer({
  title: "天地图底图",
  urlTemplate:
    "https://{subDomain}.tianditu.gov.cn/DataServer?T=vec_w&x={col}&y={row}&l={level}&tk=6985de6622c7e2f3289da48e5a69021e",
  subDomains: ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"],
});
export const tiledLayer_poi = new WebTileLayer({
  title: "天地图标注",
  urlTemplate:
    "https://{subDomain}.tianditu.gov.cn/DataServer?T=cva_w&x={col}&y={row}&l={level}&tk=6985de6622c7e2f3289da48e5a69021e",
  subDomains: ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"],
});
//天地图影像
export const imageLayer = new WebTileLayer({
  title: "天地图影像",
  urlTemplate:
    "https://{subDomain}.tianditu.gov.cn/DataServer?T=img_w&x={col}&y={row}&l={level}&tk=6985de6622c7e2f3289da48e5a69021e",
  subDomains: ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"],
});

export const initMap = () => {
  map = new Map({
    basemap: {
      baseLayers: [tiledLayer, tiledLayer_poi],
    },
  });

  mapView = new MapView({
    map: map,
    container: "viewDiv",
    zoom: 9,
    center: [114.52, 38.05],
  });
};

export const addLayers = () => {
  //添加地图服务
  map.addMany([
    sjz_county_layer,
    sjz_road_layer,
    police_layer,
    factory_layer,
    hospital_layer,
    fire_station_layer,
    river_line_layer,
    river_area_layer,
  ]);
};

export { map, mapView };
